var BASE_URL = 'http://jinzhidata.com/v2'

$(function () {
    $.ajax({
        type: "get",
        url: BASE_URL + "/getUserInfo",
        contentType: 'application/json',
        dataType: "json",
        success: function (response) {
            if (response.code === 0) {
                var data = response.data
                $("input[name=userName]").val(data.userName)
            } else if (response.code === 1001) {
                alert("您还没有登录！")
            }
        }
    })

    $("button.submit").click(function () {

        $.ajax({
            type: "post",
            url: BASE_URL + "/updateUserName",
            data: {
                userName: $("input[name=userName]").val()
            },
            dataType: "json",
            success: function (response) {
                if (response.code === 0) {
                    alert("修改成功！")
                    window.location.href = "user.html"
                } else if (response.code === 1001) {
                    alert("您还没有登录！")
                } else {
                    alert(response.msg)
                }
            }
        })
    })

})